# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=hypothesis
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.8.0
pkgrel=1
pkgdesc="Advanced Quickcheck style testing library for Python (mingw-w64)"
arch=('any')
url='https://hypothesis.readthedocs.org'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-attrs"
         "${MINGW_PACKAGE_PREFIX}-python-coverage"
         "${MINGW_PACKAGE_PREFIX}-python-sortedcontainers")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pytz: for datetime and django module"
            "${MINGW_PACKAGE_PREFIX}-python-faker: for fakefactory and django module"
            "${MINGW_PACKAGE_PREFIX}-python-django: for django module"
            "${MINGW_PACKAGE_PREFIX}-python-numpy: for numpy module"
            "${MINGW_PACKAGE_PREFIX}-python-pytest: for pytest module")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
#checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
#              "${MINGW_PACKAGE_PREFIX}-python-flake8"
#              "${MINGW_PACKAGE_PREFIX}-python-pytz"
#              "${MINGW_PACKAGE_PREFIX}-python-numpy"
#              "${MINGW_PACKAGE_PREFIX}-python-faker" 
#              "${MINGW_PACKAGE_PREFIX}-python-flaky"
#              "${MINGW_PACKAGE_PREFIX}-python-pytest-benchmark"
#              "${MINGW_PACKAGE_PREFIX}-python-django"
#              "${MINGW_PACKAGE_PREFIX}-python-pytest-xdist"
#              "${MINGW_PACKAGE_PREFIX}-python-mock"
#              "${MINGW_PACKAGE_PREFIX}-python-pandas")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/HypothesisWorks/hypothesis/archive/hypothesis-python-${pkgver}.tar.gz")
sha512sums=('60e355e2f3a03264fff852f422fcceec6ca621e28ea63e100f85ab0144a8e291e7fada78e82ad55623c0bfba971008a059bc125eff89c82d5ddfbfca88e4d43c')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"
  sed -i "/FutureWarning/a \    filterwarnings('ignore', category=DeprecationWarning, module='pandas.core')" \
       ${_realname}-${_realname}-python-$pkgver/hypothesis-python/tests/common/setup.py

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${_realname}-python-${pkgver}" "python-build-${CARCH}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
  export LC_CTYPE=en_US.UTF-8
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}/hypothesis-python"
  ${MINGW_PREFIX}/bin/python setup.py build
}

# Comment out until we can get this to work.
#check() {
#  msg "Python test for ${CARCH}"
#  cd "${srcdir}/python-build-${CARCH}/hypothesis-python"
#  mv tests/django ../
#  ${MINGW_PREFIX}/bin/python setup.py pytest --addopts -n16
#  mv ../django tests/
#  PYTHONPATH="$PWD/build/lib:$PYTHONPATH" ${MINGW_PREFIX}/bin/python -m tests.django.manage test tests.django || warning "Tests failed"
#}

package() {
  cd "${srcdir}/python-build-${CARCH}/hypothesis-python"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}
